//
//  TubiaoViewController_2.m
//  jizhiyunduan
//
//  Created by 鞠超 on 16/4/22.
//  Copyright © 2016年 JC. All rights reserved.
//

#import "TubiaoViewController_2.h"

#import "PNChartDelegate.h"
#import "PNChart.h"

@interface TubiaoViewController_2 () <PNChartDelegate>

@property (nonatomic, strong) UIScrollView * scrollView;

//背景图
@property (nonatomic, strong) UIView * view_bg;
@property (nonatomic, strong) UIView * view_bg1;

//图表
@property (nonatomic) PNPieChart * pieChart;
@property (nonatomic) PNPieChart * pieChart1;

@end

@implementation TubiaoViewController_2

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self p_navi];
    
    [self p_setupView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - navi
- (void)p_navi
{
    _lblTitle.text = [NSString stringWithFormat:@"数据访问比"];
    _lblTitle.font = [UIFont systemFontOfSize:20];
    
    [self addLeftButton:@"fanhui@2x.png"];
    
    [self addRightButton:@"shuaxin@2x.png"];
}

//左返回
- (void)clickLeftButton:(UIButton *)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}

//刷新
- (void)clickRightButton:(UIButton *)sender
{
    self.pieChart.displayAnimated = YES;
    [self.pieChart strokeChart];

    self.pieChart1.displayAnimated = YES;
    [self.pieChart1 strokeChart];
}

//隐藏tabbar
-(void)viewWillAppear:(BOOL)animated
{
    [(AppDelegate *)[[UIApplication sharedApplication] delegate] hiddenTabBar];
}

#pragma mark - 布局
- (void )p_setupView
{
    self.view.backgroundColor = [UIColor groupTableViewBackgroundColor];
    
    self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT - 64)];
    self.scrollView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    [self.view addSubview:self.scrollView];
    
    if(SCREEN_HEIGHT > 700)
    {
        self.scrollView.contentSize = CGSizeMake(0, 680);
    }
    else
    {
        self.scrollView.contentSize = CGSizeMake(0, 600 + 10 + 30);
    }
    
    [self p_tubiao];
    
    [self p_tubiao1];
}

#pragma mark - 图表——1.2
- (void)p_tubiao
{
    //背景
    self.view_bg = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 300)];
    self.view_bg.backgroundColor = [UIColor whiteColor];
    [self.scrollView addSubview:self.view_bg];
    
    
    //饼状图
    NSArray * items = @[[PNPieChartDataItem dataItemWithValue:40 color:[UIColor orangeColor] description:@"PC端"],[PNPieChartDataItem dataItemWithValue:20 color:navi_bar_bg_color description:@"手机端"],
                       ];
    
    self.pieChart = [[PNPieChart alloc] initWithFrame:CGRectMake(SCREEN_WIDTH / 2 - 100, 20, 200, 200) items:items];
    self.pieChart.descriptionTextColor = [UIColor whiteColor];
    self.pieChart.descriptionTextFont  = [UIFont systemFontOfSize:11];
    self.pieChart.descriptionTextShadowColor = [UIColor clearColor];
    self.pieChart.showAbsoluteValues = NO;
    self.pieChart.showOnlyValues = NO;
    [self.pieChart strokeChart];
    
    self.pieChart.legendStyle = PNLegendItemStyleStacked;
    self.pieChart.legendFont = [UIFont boldSystemFontOfSize:12.0f];
    
    UIView * legend = [self.pieChart getLegendWithMaxWidth:SCREEN_WIDTH];
    [legend setFrame:CGRectMake(SCREEN_WIDTH / 2 - 30, CGRectGetMaxY(self.pieChart.frame) + 20, SCREEN_WIDTH / 2, legend.frame.size.height)];
//    legend.backgroundColor = [UIColor orangeColor];
    [self.view_bg addSubview:legend];
    
    [self.view_bg addSubview:self.pieChart];

}

- (void)p_tubiao1
{
    //背景
    self.view_bg1 = [[UIView alloc] initWithFrame:CGRectMake(0, 310, SCREEN_WIDTH, 300)];
    self.view_bg1.backgroundColor = [UIColor whiteColor];
    [self.scrollView addSubview:self.view_bg1];
    
    
    //饼状图
    NSArray * items1 = @[[PNPieChartDataItem dataItemWithValue:30 color:[UIColor orangeColor] description:@"百度搜索"],[PNPieChartDataItem dataItemWithValue:11 color:navi_bar_bg_color description:@"其他"],
                        ];
    
    self.pieChart1 = [[PNPieChart alloc] initWithFrame:CGRectMake(SCREEN_WIDTH / 2 - 100, 20, 200, 200) items:items1];
    self.pieChart1.descriptionTextColor = [UIColor whiteColor];
    self.pieChart1.descriptionTextFont  = [UIFont systemFontOfSize:11];
    self.pieChart1.descriptionTextShadowColor = [UIColor clearColor];
    self.pieChart1.showAbsoluteValues = NO;
    self.pieChart1.showOnlyValues = NO;
    [self.pieChart1 strokeChart];
    
    self.pieChart1.legendStyle = PNLegendItemStyleStacked;
    self.pieChart1.legendFont = [UIFont boldSystemFontOfSize:12.0f];
    
    UIView * legend1 = [self.pieChart1 getLegendWithMaxWidth:SCREEN_WIDTH];
    [legend1 setFrame:CGRectMake(SCREEN_WIDTH / 2 - 30, CGRectGetMaxY(self.pieChart1.frame) + 20, SCREEN_WIDTH / 2, legend1.frame.size.height)];
//    legend1.backgroundColor = [UIColor orangeColor];
    [self.view_bg1 addSubview:legend1];
    
    [self.view_bg1 addSubview:self.pieChart1];
}


@end
